/**
 * @class   wosh::building::Location
 * @brief   
 *
 *
 *

Generic Location. There is hierarchy and cross relationships.

A Room is a Location! Rooms may have sub-locations (such as one defined by a motion sensor)



-----------------------------------------------------------------------------
HomeLocation is a generic zone. May be a room or part of it.
Unique formatted name. (? home:location ?)
There is hierarchy.
Zone is defined by?			room? sensor? device? has geometry?

sensormotion is a zone? yes
devices with a location property are zones (we care moslty about the parent) ? yes?
room is a zone?  yes
floor, house are zones? yes?


System:
-------
Holds list of usernames (we are guessing/evaluating and updating UserManager, so it's MAIN DB and up to date)
Settings (ex. shut up here)

Devices:
--------
Holds list of communicators URI [ordered] (usually one item) (used to route generic notification)
Holds list of PlayerAudio URI [ordered] (usually one item) (used when notifing an audio message)
Holds list of PlayerVideo URI [ordered] (usually one item) (used when notifing a video message)
---------------------------------------------------------------------------------------------------



 *
 *
 *
 *
 *
 *
 *
 ****************************************************************************
 * @version $Id: Location.h 2863 2010-08-07 04:28:58Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Building_Location_H__
 #define __WOSH_Building_Location_H__

 #include <core/Object.h>
 #include <core/InterfacesProvider.h>
 #include <core/MethodsProvider.h>
 #include <core/PropertiesProvider.h>
// #include <core/UserInfoLocation.h>
 #include <core/Containers.h>
 #include <core/Method.h>
 #include <core/Request.h>

 #include <vector>
 #include <map>


namespace wosh {
 namespace building {

 #define _Location_VERSION			0.02

struct PointLatLong {
	double latitude;			///< latitude of the location (optional) [North is positive]
	double longitude;			///< longitude of the location (optional) [East is positive]
	double latlong_variance;	///< variance of the lat/long position (optional)
 };


class Location :	public Object,
					public virtual IPropertiesProviderListener,
				//	public virtual IBusListener,
					protected MethodRunner
 {
	WOSH_SERIALIZABLE(wosh::building::Location)

	typedef MapT<std::string, void*> tStrLocationAccessInfoMap;


	public:
		enum LOCATION_TYPE {
			TYPE_UNKNOWN	= 0x00,
			TYPE_BUILDING	= 0x01,
			TYPE_DEVICE		= 0x02,
			TYPE_VIRTUAL	= 0x08,
			TYPE_GENERIC	= 0x16
		 };
		enum LOCATION_CATEGORY {
			CATEGORY_UNKNOWN	= 0x00,
			CATEGORY_HOME		= 0x01,
			CATEGORY_WORK		= 0x02,
			CATEGORY_FRIEND		= 0x08,
			CATEGORY_GENERIC	= 0x16
		 };


	public:
		/**
		 * @brief  Empty constructor.
		 */
		Location();
		/**
		 * @brief  Copy constructor.
		 * @param m [in] the source object to be copied
		 */
		Location( const Location& m );
		/**
		 * @brief  Empty destructor.
		 */
		virtual ~Location() { }


	public:
	// to do for convenience:
	//	bool isUserInLocation( const std::string& username ) const;


/** @name Getters
 * @{
 ******************************************************************************/
	public:
		const std::string& getParentName() const			{ return this->parentName; }

		LOCATION_TYPE getLocationType() const				{ return this->locationType; }
		LOCATION_CATEGORY getLocationCategory() const		{ return this->locationCategory; }

		const std::map<std::string, double>& getAccessTo() const	{ return this->accessTo; }
		std::map<std::string, double>& getAccessTo()				{ return this->accessTo; }

//@}
/** @name Setters
 * @{
 ******************************************************************************/
	public:
		void setParentName( const std::string& value );

		void setLocationType( LOCATION_TYPE type );
		void setLocationCategory( LOCATION_CATEGORY category );

		void setAccessTo( Location* location, double probability = -1.0 );
		void setAccessTo( const std::string& location, double probability = -1.0 );

//@}
/** @name IPropertiesProviderListener interface
 * @{
 ******************************************************************************/
 	public:
		virtual inline bool readingProperty( Property* , const PropertiesProvider* ) { return true; }
		virtual bool updatingProperty( bool& do_update, const Variant& value_proposed, Property& property_current, const PropertiesProvider* source );
//@}
/** @name Serialization interface
 * @{
 ******************************************************************************/
	public:
		virtual bool updateHash( DataHashContext* hash_context ) const;
//@}
	protected:
		std::string parentName;				///< parent location
		LOCATION_TYPE locationType;
		LOCATION_CATEGORY locationCategory;
//MapT
		std::map<std::string, double> accessTo;	///< locations may be accessed (default probability)

		PointLatLong position;
		MethodsProvider Methods;		///< implemented methods
		PropertiesProvider Properties;	///< hosted properties
		InterfacesProvider Interfaces;	///< supported interfaces (names)


}; // class def

 }; // namespace building
}; // namespace wosh

#endif //__WOSH_Building_Location_H__
